using System;
using System.Data;
using GoodsInvoicing.Model.Menu;
using GoodsInvoicing.DAL.DAO;
using System.Collections.Generic;

namespace GoodsInvoicing.DAL.Hibernate
{
    /// <summary>
    /// 表[GI_Menu]的Hibernate类实现
    /// </summary>
    public class GI_MenuDAOHibernate : BaseHibernate<GI_Menu, int>, GI_MenuDAO
    {
        public IDictionary<GI_Menu, IList<GI_Menu>> GetMenus(string loginName)
        {
            IList<GI_Menu> firstLevelMenus = HibernateTemplate.Find<GI_Menu>("from GI_Menu m where m.ParentID = 0 order by m.MenuSequence");
            IDictionary<GI_Menu, IList<GI_Menu>> menuDict = new Dictionary<GI_Menu, IList<GI_Menu>>();
            foreach (var menu in firstLevelMenus)
            {
                IList<GI_Menu> secondLevelMenus = HibernateTemplate.Find<GI_Menu>("from GI_Menu m where m.ParentID = ? order by m.MenuSequence", new object[]{ menu.MenuID});
                menuDict.Add(menu, secondLevelMenus);
            }
            return menuDict;
        }
    }
}
